<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='./02/js/vue.js'></script>
</head>

<body>
    <div id='app'>
        <p v-bb='dd'>{{msg | fff}}</p>

        <span>=={{f1|fff2(44444)}}===</span>

        <hr>
        ========================================
        <ul>
            <li v-for="(item, index) in list" :key="index">
                <input type="checkbox" v-model='item.flag'>
                品牌：<span>{{item.name}}</span>
                价格：<span>{{item.price}}</span>
                数量：<span>{{item.num}}</span>==={{item.flag}}
            </li>
        </ul>
        总价：0元=={{total}}
    </div>
    <script type='text/javascript'>

        Vue.directive('aa', {
            inserted(el, binding) {
                console.log(binding.value.color);
                el.style.color = binding.value.color

            },
            bind() {

            }
        })

        Vue.filter('ff', function (msg) {
            return msg.replace('world', 'vue')
        })



        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue',
                dd: {
                    color: "blue"
                },
                f1: 'hello  world',
                list:[
                    {id:1,name:'安踏',price:110,num:3,flag:false},
                    {id:2,name:'李宁',price:210,num:4,flag:false},
                    {id:3,name:'特步',price:310,num:6,flag:false},
                    {id:4,name:'耐克',price:410,num:9,flag:false},
                ]
            },
            directives: {
                bb: {
                    inserted(el, binding) {
                        console.log(binding.value.color);
                        el.style.color = binding.value.color

                    },
                    bind() {

                    }
                }
            },
            filters:{
                fff(msg){
                    return msg.replace('Vue', 'vue123')
                },
                fff2(msg,str){
                    return msg+str
                }
            },
            computed: {
                total(){
                    var  sum=0;
                    var  arrTrue=this.list.filter(function(item){
                        return  item.flag
                    })
                    arrTrue.forEach((item,i)=>{
                        sum+=item.price*item.num
                    })

                    return sum
                }
            },  
        });
    </script>
</body>

</html>